<html>
<head>
  <title>Simple DB</title>
</head>

<body>
This is to do minimal db work.

<input type="text" name="in" id="in" />
<input type="button" onclick="insert()" value="INSERT" />
<input type="button" onclick="show()" value="SHOW" />

<div id="output"></div>

<script runat="server">
function $(id) { return document.getElementById(id); }

(function() {

  var db = new Jaxer.DB.SQLite.Connection({ PATH: 'resource:///../data/simpledb.sqlite', CLOSE_AFTER_EXECUTE: 'open' });
//  Jaxer.DB.SQLite.createDB({ PATH: 'resource:///../data/simpledb.sqlite'});
  db.execute("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(256) )");
  db.execute("INSERT INTO test (name) VALUES (?)", [ 'value' ]);
  
  var rs = db.execute("SELECT * FROM test");
  for (var i=0, len = rs.rows.length; i<len; i++) {
		var row = rs.rows[i];
		$('output').innerHTML += row['name'];
	}
	db.close();
})();
</script>
</body>
</html>
